package com.ehsy.statement;

import com.ehsy.common.ResponseVo;
import com.ehsy.service.PathService;
import com.ehsy.service.PathService2;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author YanZhen_Li
 * @version 1.0
 * @title 路径赋值
 * @description
 * @create 2024/6/17 14:55
 */
@SpringBootTest
public class A2路径赋值 {
    @Resource
    PathService pathService;

    @Resource
    PathService2 pathService2;

    /**
     * 简单路径替换
     */
    @Test
    void pathTest() {
        ResponseVo<Object> test1 = pathService.test1("http://localhost:8080/test/request/json/body");
        ResponseVo<Object> test2 = pathService.test2("http://localhost:8080/test/request/json/body");
        ResponseVo<Object> test3 = pathService.test3("myTestPath");
        ResponseVo<Object> test4 = pathService.test4("body");
        System.out.println(test1);
        System.out.println(test2);
        System.out.println(test3);
        System.out.println(test4);
    }

    /**
     * 请求统一地址
     */
    @Test
    void pathTest2() {
        ResponseVo<Object> test1 = pathService2.sendData1();
        ResponseVo<Object> test2 = pathService2.sendData2();
        System.out.println(test1);
        System.out.println(test2);
    }

    /**
     * 动态请求地址，用于多个请求源
     */
    @Test
    void pathTest3(){
        List<ResponseVo<Object>> responseList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ResponseVo<Object> responseVo = pathService2.sendData3();
            responseList.add(responseVo);
        }
        responseList.forEach(vo->{
            System.out.println(vo.getData().getUrl());
        });
    }
}
